package main

import (
	"os"
	"os/signal"
	"time"
	"trade/huobiapi/order"
	"trade/logger"
)

func main() {
	_ = os.Setenv("HUOBI_DEBUG", "1")
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		<-c
		logger.Log.Info("Got Control+C, exiting...")
		os.Exit(0)
	}()
	if len(os.Args) < 2 {
		logger.Log.Info("配置文件缺失")
		os.Exit(0)
	}
	cfile := os.Args[1]
	//配置
	huobiO, err := order.NewHuobiOrder(cfile)
	if err != nil {
		logger.Log.Fatal(err)
		return
	}

	err = huobiO.CheckPosition(time.Now().Unix() - 15*60)
	if err != nil {
		logger.Log.Fatal(err)
		return
	}
	go huobiO.CreateOrder()
	time.Sleep(1 * time.Second)
	huobiO.Subscribe()
}
